package com.ruoyi.web.controller.ability;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GoodsPic;
import com.ruoyi.system.service.IGoodsPicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品图片Controller
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/system/pic")
public class GoodsPicController extends BaseController
{
    @Autowired
    private IGoodsPicService goodsPicService;

    /**
     * 查询商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:pic:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsPic goodsPic)
    {
        startPage();
        List<GoodsPic> list = goodsPicService.selectGoodsPicList(goodsPic);
        return getDataTable(list);
    }

    /**
     * 导出商品图片列表
     */
    @PreAuthorize("@ss.hasPermi('system:pic:export')")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsPic goodsPic)
    {
        List<GoodsPic> list = goodsPicService.selectGoodsPicList(goodsPic);
        ExcelUtil<GoodsPic> util = new ExcelUtil<GoodsPic>(GoodsPic.class);
        util.exportExcel(response, list, "商品图片数据");
    }

    /**
     * 获取商品图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pic:query')")
    @GetMapping(value = "/{picId}")
    public AjaxResult getInfo(@PathVariable("picId") Long picId)
    {
        return success(goodsPicService.selectGoodsPicByPicId(picId));
    }

    /**
     * 新增商品图片
     */
    @PreAuthorize("@ss.hasPermi('system:pic:add')")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsPic goodsPic)
    {
        return toAjax(goodsPicService.insertGoodsPic(goodsPic));
    }

    /**
     * 修改商品图片
     */
    @PreAuthorize("@ss.hasPermi('system:pic:edit')")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsPic goodsPic)
    {
        return toAjax(goodsPicService.updateGoodsPic(goodsPic));
    }

    /**
     * 删除商品图片
     */
    @PreAuthorize("@ss.hasPermi('system:pic:remove')")
    @Log(title = "商品图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{picIds}")
    public AjaxResult remove(@PathVariable Long[] picIds)
    {
        return toAjax(goodsPicService.deleteGoodsPicByPicIds(picIds));
    }
}
